export function sendCommand(then,commandStr, key) {
    commandStr = commandStr.trim();
    let msg = {type:2,sessionKey:key,content:{command: commandStr},environment : then.environment}
    let ws = then.$store.getters.getWs;
    ws.send(JSON.stringify(msg));
}

export function generateKey(){
    return new Date().getTime();
}


//按下enter键
export function kekDownEnter(then ,tab){
    let command = tab.content.substring(tab.inputCount);
    saveHistory(command, tab);
    sendCommand(then, command, tab.source.sessionKey, then.environment);
}

//保存历史命令记录
export function saveHistory(command, tab){
    if(command.trim != ''){
        let flag = false;
        for(let i in tab.historyCommand){
            if(tab[i] == command.trim){
                flag = true;
            }
        }
        if(!flag){
            tab.historyCommand.push(command.trim);
            tab.historyCommandPoint = tab.historyCommand.length;
        }
    }
}